package main.剑指OfferⅠ;

import java.util.ArrayList;
import java.util.List;

public class Day5 {
    public static void main(String[] args) {
        System.out.println("剑指Offer04.二维数组中的查找");
        System.out.println("剑指Offer11.旋转数组的最小数字");
        System.out.println("剑指Offer50.第一个只出现一次的字符");
    }
}

class Offer04{
    public boolean process(int[] arr,int target){
        int left=0,right=arr.length-1;
        while (left<=right){
            int mid=left+(right-left)/2;
            if (arr[mid]==target) return true;
            else if (arr[mid]<target) left=mid+1;
            else right=mid-1;
        }
        return false;
    }
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix.length==0) return false;
        int n= matrix.length,m=matrix[0].length;
        for (int[] arr:matrix){
            if (m>0&&(arr[0]>target||arr[m-1]<target)) continue;
            if (process(arr,target)) return true;
        }
        return false;
    }
}

class Offer11{
    public int minArray(int[] numbers) {
        int min=Integer.MAX_VALUE;
        for (int number:numbers) min=Math.min(min,number);
        return min;
    }
}

class Offer50{
    public char firstUniqChar(String s) {
        char[] str=s.toCharArray(),counts=new char[26];
        List<Character> list=new ArrayList<>();
        char result=' ';
        for (char c:str){
            counts[c-'a']++;
            if (!list.contains(c)) list.add(c);
        }
        for (int i=0;i<list.size();i++){
            char temp=list.get(i);
            if (counts[temp-'a']==1){
                result=temp;
                break;
            }
        }
        return result;
    }
}